package com.finance.action.admin;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.finance.entity.LoanBasic;
import com.finance.entity.User;
import com.finance.entity.YhUser;
import com.finance.service.LoanBasicService;
import com.finance.service.YhUserService;
import com.web.utils.DateUtil;
import com.web.utils.UserManagerUtil;

@Controller("adminIndexAction")
@RequestMapping("admin")
public class IndexAction {

	@Resource(name = "adminLoanBasicService")
	private LoanBasicService loanBasicService;

	@Resource(name = "YhUserService")
	private YhUserService yhUserService;

	@RequestMapping("index.htm")
	public String index(Model model, YhUser record) {
		User user = UserManagerUtil.getCurrentUser();
		model.addAttribute("user", user);

		List<LoanBasic> list = loanBasicService.findByState(0);
		for (int i = 0; i < list.size(); i++) {
			Date t = new Date();
			String tt = DateUtil.toStringXiumaDateTime(t);
			Integer Year = Integer.parseInt(tt.substring(0, 4));
			Integer mouth = Integer.parseInt(tt.substring(4, 6));
			Integer nowDay = Integer.parseInt(tt.substring(6, 8));

			String bri = DateUtil.toStringXiumaDateTime(list.get(i)
					.getStillTime());
			Integer briYear = Integer.parseInt(bri.substring(0, 4));
			Integer briMouth = Integer.parseInt(bri.substring(4, 6));
			Integer briDay = Integer.parseInt(bri.substring(6, 8));
			if (Year == briYear) {
				if (mouth == briMouth) {
					if (nowDay > briDay) {
						record.setLoanState(3);
						yhUserService.updateByPrimaryKeySelective(record);
					}
				} else if (mouth > briMouth) {
					record.setLoanState(3);
					yhUserService.updateByPrimaryKeySelective(record);
				}
			} else if (mouth > briMouth) {
				record.setLoanState(3);
				yhUserService.updateByPrimaryKeySelective(record);
			}
		}
		return "manage/index";
	}

}
